#include "led.h"

void led_fun(char *uled)
{
    uint8_t temp = 0x00;
    static uint8_t temp_old = 0xff;

    for (uint8_t i = 0; i < 8;i++)
        temp |= uled[i] << i;

        if(temp != temp_old)
        {
            GPIOC->ODR &= 0x00ff;
            GPIOC->ODR |= ~(temp << 8);

            GPIOD->BSRR |= 0x01 << 2;
            GPIOD->BRR |= 0x01 << 2;

            temp_old = temp;
        }
}

uint8_t uled[8] = {0,0,0,0,0,0,0,0};
uint32_t led_time = 0;
uint8_t led_flag = 0;
void led_proc(void)
{
    uled[7] = !data1.mode;
    uled[0] = data1.GEAR == 1;
    uled[1] = data1.GEAR == 2;
    uled[2] = data1.GEAR == 3;

    if(rx_finish_flag)
    {
        led_flag = 1;
        
    }

    if(led_flag)
    {
        uled[3] = 1;
        uint32_t current_time = HAL_GetTick();
        if(current_time - led_time > 3000)
        {
            uled[3] = 0;
            led_flag = 0;
            current_time = led_time;
        }
    }

    led_fun(uled);
}
